﻿@namespace BootstrapBlazor.Components
@inherits ComponentBase
@typeparam Model

<BusinessFormViewer GetRenderPropertyInfo=GetRenderPropertyInfo
                    Verify=Verify InitializationModel="InitializationModel"
                    ExistingForms=ExistingForms IsReadOnlyProperty=IsReadOnlyProperty
                    OnPropertyChangeed=OnPropertyChangeed ShowSubmit=ShowSubmit
                    IsValueReference=IsValueReference Delete="Delete" Cancellation="Cancellation"
                    RefreshTarget="RefreshTarget" ResetAfterSubmission=ResetAfterSubmission Resetting="Resetting"
                    Submit="Submit" VerifyFail="VerifyFail">
    <RenderComponent>
        @if (RenderComponent is null)
        {
            <div class="bootstrapFormViewerTopContainer">
                @context.RenderMain
                <div />
                @context.RenderSubmit
            </div>
        }
        else
        {
            @RenderComponent(context)
        }
    </RenderComponent>
    <RenderMain>
        @if (RenderMain is null)
        {
            <div class="bootstrapFormViewerContainer">
                @foreach (var renderGroup in context.RenderGroup)
                {
                    @renderGroup.RenderRegionAll()
                }
            </div>
        }
        else
        {
            @RenderMain(context)
        }
    </RenderMain>
    <RenderProperty>
        @if (RenderProperty is null)
        {
            @if (context is RenderFormViewerPropertyInfo<Model> renderProperty)
            {
                <BootstrapFormViewerProperty RenderInfo="renderProperty" />
            }
        }
        else
        {
            @RenderProperty(context)
        }
    </RenderProperty>
    <RenderSubmit>
        @if (RenderSubmit is null)
        {
            <Center>
                <Button Text="@(context.ExistingForms?"修改":"提交")" OnClick="context.Submit"></Button>
                <Button Text="重置" OnClick="context.Resetting"></Button>
                @if (context.Delete is { } deleteValue)
                {
                    <Button Text="删除" OnClick="deleteValue"></Button>
                }
                @if (context.Cancellation is { } cancellationValue)
                {
                    <Button Text="取消" OnClick="cancellationValue"></Button>
                }
            </Center>
        }
        else
        {
            @RenderSubmit(context)
        }
    </RenderSubmit>
</BusinessFormViewer>